package com.x.erp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.ImageType;
import com.x.erp.rpc.ImageTypeRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 图片类型信息
 */
@RestController
@RequestMapping("/imageType")
public class ImageTypeController extends BaseController{

	@Reference
	private ImageTypeRpcService imageTypeRpcService;//图片场景信息服务

	/**
	 * 查询图片类型信息列表
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getImageTypeList", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getImageTypeList(ImageType imageType) {
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", imageTypeRpcService.selectImageTypeList(imageType));
	}

	/**
	 * 查询图片类型信息数量
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getImageTypeNum", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getImageTypeNum(ImageType imageType) {
		Map<String, Object> res = new HashMap<>();
		res.put("total", imageTypeRpcService.selectImageTypeNum(imageType));
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", res);
	}

	/**
	 * 新增图片类型信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/insertImageType", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel insertImageType(ImageType imageType) {
		if (StringUtils.isEmpty(imageType.getImageTypeKey())){
			return new ResultModel(ResultCode.RESULT_FAIL, "图片类型KEY不能为空！");
		}
		if (StringUtils.isEmpty(imageType.getImageTypeName())){
			return new ResultModel(ResultCode.RESULT_FAIL, "图片类型名称不能为空！");
		}
		return new ResultModel(ResultCode.RESULT_SUCCESS, "插入成功！", imageTypeRpcService.insertImageType(imageType));
	}

}
